//
//  GoodsDetailVC.m
//  reSearchDemo
//
//  Created by 云库 on 15/9/22.
//  Copyright (c) 2015年 Kiwaro. All rights reserved.
//

#import "GoodsDetailVC.h"
#import "MJExtension.h"
#import "UIView+Category.h"
#import "PhotoSeeViewController.h"
#import "GoodsDetailVC.h"
#import "ChooseSizeVC.h"
#import "BuyNowVC.h"
#import "Specval.h"
#import "GoodsParam.h"
#import "UIButton+Category.h"
#import "BusinessPlatformVC.h"
#import "UIImageView+WebCache.h"
#import "LineLable.h"
#import "ShopCarVC.h"
#import "MoreGoodsDetailVC.h"
#import "GoodsCarList.h"
@interface GoodsDetailVC()<UITextFieldDelegate,UIScrollViewDelegate,UIScrollViewDelegate> {
    int number;   /**< 商品数量 */
}

@property (strong, nonatomic) GoodsDetail *deal;

/** 主界面的scrolView*/
@property (strong, nonatomic) UIScrollView *scrolView;
/** 头部滚动视图*/
@property (strong, nonatomic) UIScrollView *hearderView;
/** 加入购物车所需的参数id*/
@property (strong, nonatomic) NSString *specId;
/** 滚动视图控制器 */
@property (strong, nonatomic) UIPageControl *pageControl;

@end




@implementation GoodsDetailVC


- (void)viewWillAppear:(BOOL)animated{
    
}

- (void)viewDidLoad{
    
    self.view.backgroundColor = [UIColor lightGrayColor];
    //加载主界面的滚动视图
    self.scrolView =[[UIScrollView alloc]initWithFrame:self.view.frame];
    self.scrolView.backgroundColor=[UIColor groupTableViewBackgroundColor];
    self.scrolView.contentSize = CGSizeMake(self.view.width, 800);
    self.scrolView.showsHorizontalScrollIndicator = NO;
    self.scrolView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.scrolView];
    
    //右上角购物车按钮
    [self setRightBarButtonImage:[UIImage imageNamed:@"购物车.png"] highlightedImage:nil selector:@selector(shopCar)];
    //获取数据
    [self loadDataFromServer];
    
    //监听通知---选择规格的改变
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(SpecDidChange:) name:@"SpecDidChange" object:nil];
    
    self.title = self.shopName;
    
}

/** 规格改变了*/

- (void)SpecDidChange:(NSNotification *)notification{

    NSString *SelectedCitySpecId = notification.userInfo[@"SelectedCitySpecId"];
    NSString *Number = notification.userInfo[@"Number"];
    self.specId = SelectedCitySpecId;
    number = [Number intValue];
}

/**
 * 所有子视图
 */
- (void)createSubViews{
    //头部滚动视图
    [self createHeaderView];
    
    //其他视图
    [self createOtherView];
    
    //底部按钮工具条
    [self createFooterView];
}


#pragma mark --底部视图--
- (void)createFooterView{
    UIView * footerView=[[UIView alloc]initWithFrame:CGRectMake(0, self.view.height-50, self.view.width, 50)];
    footerView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:footerView];
    NSArray * arr=@[@"客服",@"店铺",@"收藏"];
    for (int i=0; i<3; i++) {
        UIButton * btn=[UIButton buttonWithType:UIButtonTypeSystem];
        btn.frame=CGRectMake(i*50, 0, 49, 50);
        [btn setTitle:[NSString stringWithFormat:@"%@",arr[i]] forState:UIControlStateNormal];
        btn.backgroundColor=[UIColor grayColor];
        [btn addTarget:self action:@selector(threeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag=30+i;
        [footerView addSubview:btn];
    }
    //加入购物车按钮
    UIButton * addShopCar=[UIButton buttonWithType:UIButtonTypeSystem];
    addShopCar.frame=CGRectMake(150, 0, (self.view.frame.size.width-150)/2, 50);
    [addShopCar setTitle:@"加入购物车" forState:UIControlStateNormal];
    addShopCar.backgroundColor=[UIColor orangeColor];
    [addShopCar addTarget:self action:@selector(addShopCarNow) forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:addShopCar];
    
    //立即购买按钮
    UIButton * buyNow=[UIButton buttonWithType:UIButtonTypeSystem];
    buyNow.frame=CGRectMake(addShopCar.frame.origin.x+addShopCar.frame.size.width, 0, (self.view.frame.size.width-150)/2, 50);
    buyNow.backgroundColor=[UIColor redColor];
    [buyNow setTitle:@"立刻购买" forState:UIControlStateNormal];
    [buyNow addTarget:self action:@selector(buyNowClick:) forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:buyNow];

}

/** 客服-店铺-收藏按钮*/
- (void)threeBtnClick:(UIButton *)button{
   
}

#pragma mark --加入购物车--
- (void)addShopCarNow{
    /**
     http://mall.yunku.mobi:8080/mall/widget.html              ===ok===
     http://mall.yunku.mobi:8080/mall/widget.html?widget=carsWidget&dataType=json&action=add&n=1&i=11&spec=&g_id=53&huiYuan_id=83        ===ok===
     n=商品数量  i=随机数  spec=商品参赛id  g_id=商品id 53    huiYuan_id 会员id
     */
    if (self.specId==nil) {//没有选择规格参数提醒
//        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"请选择规格" message:@"选择规格后才可以加入购物车！" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//        [alertView show];
        ChooseSizeVC *choose = [[ChooseSizeVC alloc] init];
        /** 获取规格 参数是goodID*/
        choose.goods = self.deal;
        
        [self pushViewController:choose];
    }else{
        //加入购物车
        static  int good_id;
        
        if (good_id == self.goodId) {
            UIAlertView * alter=[[UIAlertView alloc]initWithTitle:@"抱歉" message:@"该商品已经加入购物车" delegate:nil cancelButtonTitle:@"退出" otherButtonTitles:nil, nil];
            [alter show];
            
        }else{
            NSString *path = [NSString stringWithFormat:@"%@%@",SHOPER,@"widget.html"];
            NSDictionary *dic = @{@"widget":@"carsWidget",@"dataType":@"json",@"action":@"add",@"n":[NSString stringWithFormat:@"%d",number],@"i":@"11",@"spec":self.specId,@"g_id":[NSString stringWithFormat:@"%d",self.goodId],@"huiYuan_id":@"83"};
        AFHTTPRequestOperationManager * manager=[AFHTTPRequestOperationManager manager];
        [manager GET:path parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSDictionary * dict=(NSDictionary*)responseObject;
            if ([[dict objectForKey:@"status"]integerValue]==1) {
                UIAlertView * alert=[[UIAlertView alloc]initWithTitle:@"抱歉" message:[dict objectForKey:@"msg"] delegate:nil cancelButtonTitle:@"退出" otherButtonTitles:nil, nil];
                [alert show];
            }else if ([[dict objectForKey:@"status"]integerValue]==0){
                UIAlertView * alert=[[UIAlertView alloc]initWithTitle:@"恭喜" message:@"加入购物车成功" delegate:nil cancelButtonTitle:@"退出" otherButtonTitles:nil, nil];
                [alert show];
                 good_id=self.goodId;
            }
            DLog(@"%@",responseObject);
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            DLog(@"error = %@",error);
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示:" message:@"加入购物车失败!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
        }];
       
        }
    }
}

#pragma mark --立即购买按钮--
- (void)buyNowClick:(UIButton *)button{
    NSMutableArray *arr = [NSMutableArray array];
    NSArray * imgArr1=[self.deal.images componentsSeparatedByString:@";"];
    NSMutableArray * imgArr=[NSMutableArray arrayWithArray:imgArr1];
    if ([[imgArr objectAtIndex:imgArr.count-1] isEqualToString:@""]) {
        [imgArr removeObjectAtIndex:imgArr.count-1];
    }
    NSString * string=[NSString stringWithFormat:@"http://mall.yunku.mobi:8080/mall/upload/goods/%@",[imgArr lastObject]];
    GoodsCarList *goods = [[GoodsCarList alloc] init];
    goods.image = string;
    goods.shopname = self.shopName;
    goods.money = self.deal.money;
    goods.num = 1;
    [arr addObject:goods];
    BuyNowVC *buyVc = [[BuyNowVC alloc] init];
    buyVc.model = arr;
    [self pushViewController:buyVc];
}

#pragma mark --内容视图--
- (void)createOtherView{
    
    UIView *NamebgView = [[UIView alloc] initWithFrame:CGRectMake(0, self.hearderView.height, CGRectGetWidth(self.view.frame), 40)];
    NamebgView.backgroundColor = [UIColor colorWithRed:212/255.0 green:212/255.0 blue:212/255.0 alpha:0.9];
    [self.scrolView addSubview:NamebgView];
    //1.分享
    UIView *shareLan = [[UIView alloc] initWithFrame:CGRectMake(self.view.width-30, 0, 1, 40)];
    shareLan.backgroundColor = [UIColor lightGrayColor];
    [NamebgView addSubview:shareLan];
    
    
    UIButton *shareBtn = [UIButton buttonWithTarget:self action:@selector(shareBtnClick:) image:@"分享图标.png"];
    shareBtn.frame = CGRectMake(self.view.width-25,5, 20, 20);
    [NamebgView addSubview:shareBtn];
    
    UILabel * shareLab=[[UILabel alloc]initWithFrame:CGRectMake(self.view.width-30, shareBtn.y+shareBtn.height, 30, 20)];
    shareLab.text=@"分享";
    shareLab.font = [UIFont systemFontOfSize:10];
    shareLab.textAlignment=NSTextAlignmentCenter;
    shareLab.textColor=[UIColor grayColor];
    [NamebgView addSubview:shareLab];
    
    //2.名称
    UILabel * nameLab=[[UILabel alloc]initWithFrame:CGRectMake(10,0, self.view.width-shareBtn.width - 20, NamebgView.height)];
   
    nameLab.text= self.deal.goodName;
    nameLab.numberOfLines=0;
    nameLab.font = [UIFont systemFontOfSize:13];
    [NamebgView addSubview:nameLab];
    DLog(@"-------%@",self.deal.goodName);
    
    UIView *PriceBGView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(NamebgView.frame), CGRectGetWidth(self.view.frame), 40)];
    PriceBGView.backgroundColor = [UIColor lightGrayColor];
    [self.scrolView addSubview:PriceBGView];
    //3.价格
    UILabel * newPrice=[[UILabel alloc]initWithFrame:CGRectMake(nameLab.frame.origin.x+5, 10, 120, 20)];
    newPrice.textColor=[UIColor redColor];
    float money=self.deal.money;
    newPrice.text=[NSString stringWithFormat:@"¥现价:%.2f",money];
    newPrice.font=[UIFont systemFontOfSize:20];
    [PriceBGView addSubview:newPrice];
    
    UILabel * phonePrice = [[UILabel alloc] initWithFrame:CGRectMake(self.view.width - 80, 5, 70, 20)];
    phonePrice.text = @"手机专享价";
    phonePrice.font = [UIFont systemFontOfSize:13];
    phonePrice.backgroundColor = [UIColor yellowColor];
    [PriceBGView addSubview:phonePrice];
    
    LineLable * price=[[LineLable alloc]initWithFrame:CGRectMake(newPrice.frame.origin.x, CGRectGetMaxY(PriceBGView.frame), newPrice.frame.size.width, 15)];
    float xmoney=self.deal.xmoney;
    price.text=[NSString stringWithFormat:@"原价:%.2f",xmoney];
    price.textColor=[UIColor grayColor];
    price.font=[UIFont systemFontOfSize:15];
    [self.scrolView addSubview:price];


    //4.快递
    UILabel * express=[[UILabel alloc]initWithFrame:CGRectMake(price.frame.origin.x, price.frame.origin.y+price.frame.size.height+10, 100, 10)];
    express.textColor=[UIColor grayColor];
    express.text=@"快递:免运费";
    express.font=[UIFont systemFontOfSize:15];
    [self.scrolView addSubview:express];
    
    //5.地址
    UIButton * locationBtn=[UIButton buttonWithType:UIButtonTypeSystem];
    locationBtn.frame=CGRectMake(self.scrolView.frame.size.width-80, express.frame.origin.y, 100, 10);
    //[locationBtn setTitle:self.address forState:UIControlStateNormal];
    [locationBtn addTarget:self action:@selector(locationBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.scrolView addSubview:locationBtn];
    
    //灰色背景
    UIView *bgView=[[UIView alloc]initWithFrame:CGRectMake(0, locationBtn.y+locationBtn.frame.size.height+10, self.view.width, 50)];
    bgView.backgroundColor=[UIColor grayColor];
    [self.scrolView addSubview:bgView];

    //选择规格
    UIButton * choiseBtn=[UIButton buttonWithType:UIButtonTypeSystem];
    choiseBtn.frame=CGRectMake(0, bgView.frame.origin.y+bgView.frame.size.height, self.scrolView.frame.size.width, 50);
    [choiseBtn setTitle:@"选择规格" forState:UIControlStateNormal];
    choiseBtn.tintColor=[UIColor blackColor];
    choiseBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    choiseBtn.backgroundColor = [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:0.9];
    [choiseBtn addTarget:self action:@selector(chooseBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.scrolView addSubview:choiseBtn];
    
    //评价
    UILabel * commentLab=[[UILabel alloc]initWithFrame:CGRectMake( 10, choiseBtn.frame.size.height+choiseBtn.frame.origin.y+10, 150, 20)];
    commentLab.text=@"宝贝评价（418）";
    [self.scrolView addSubview:commentLab];
    
    //评论列表
    UILabel *commentContent = [[UILabel alloc] init];
    commentContent.text = @"X****Y:其实我穿稍微有点大,老公说不要换了,太麻烦,就这样留下吧,还是很好看的";
    commentContent.numberOfLines = 0;
    commentContent.textColor = [UIColor lightGrayColor];
    commentContent.backgroundColor = [UIColor colorWithRed:220/255.0 green:220/255.0 blue:220/255.0 alpha:0.9];
    commentContent.font = [UIFont systemFontOfSize:14];
    CGSize size = [commentContent.text boundingRectWithSize:CGSizeMake(self.view.frame.size.width, 80) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: commentContent.font} context:nil].size;
    commentContent.frame = CGRectMake(0, commentLab.frame.size.height+commentLab.frame.origin.y+5, CGRectGetWidth(self.view.frame), size.height);
    DLog(@"commentContent = %@",commentContent);
    [self.scrolView addSubview:commentContent];
    //规格
    UILabel *evaluationTimeLab=[[UILabel alloc]initWithFrame:CGRectMake(5, commentContent.frame.origin.y+commentContent.frame.size.height + 5, 250, 10)];
    evaluationTimeLab.text=@"2015-06-26 颜色分类：黑色：尺码：M";
    evaluationTimeLab.font=[UIFont systemFontOfSize:13];
    evaluationTimeLab.textColor=[UIColor grayColor];
    [self.scrolView addSubview:evaluationTimeLab];
    
    
//    UITextField * textField=[[UITextField alloc]initWithFrame:CGRectMake(5, commentLab.frame.size.height+commentLab.frame.origin.y+5, self.scrolView.frame.size.width-10, 60)];
//    textField.borderStyle=UITextBorderStyleRoundedRect;
//    textField.placeholder=@"有什么想说的吗";
//    textField.delegate=self;
//    [self.scrolView addSubview:textField];

    
    UILabel *commentName=[[UILabel alloc]initWithFrame:CGRectMake(5, choiseBtn.y+choiseBtn.height+95, 200, 30)];
    //commentName.text=@"八＊＊早";
    commentName.font=[UIFont systemFontOfSize:17];
    [self.scrolView addSubview:commentName];
    
     UILabel *evaluationLab=[[UILabel alloc]initWithFrame:CGRectMake(commentName.x, commentName.y+commentName.height, self.view.frame.size.width-10, 45)];
    //evaluationLab.text=@"一次买了4件，用来搭配衣服的，包装很好，买之前问过客服的建议，买了M吗，拿了意见过水后，缩水了，后来联系客服将其它的。。";
    evaluationLab.numberOfLines=0;
    evaluationLab.font=[UIFont systemFontOfSize:15];
    [self.scrolView addSubview:evaluationLab];
    
    
    
    //更多评价
    UIButton * moreCommentBtn=[UIButton buttonWithType:UIButtonTypeSystem];
    moreCommentBtn.frame=CGRectMake(0, evaluationTimeLab.frame.origin.y+evaluationTimeLab.size.height+5, self.view.frame.size.width, 40);
    [moreCommentBtn setTitle:@"查看更多评价" forState:UIControlStateNormal];
    moreCommentBtn.backgroundColor=[UIColor grayColor];
    moreCommentBtn.tintColor=[UIColor blackColor];
    [moreCommentBtn addTarget:self action:@selector(moreCommentBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.scrolView addSubview:moreCommentBtn];
    
    
    //宝贝分类
    UIButton * seeClassification=[UIButton buttonWithTarget:self action:@selector(seeClassification) image:@"云平台.png"];
    [UIView SetRoundedCorners:seeClassification andcornerRadius:10.0 andborderWidth:1.0 andborderColor:[UIColor clearColor]];
    seeClassification.frame=CGRectMake((CGRectGetWidth(self.scrolView.frame)-80*2)/3, moreCommentBtn.frame.origin.y+moreCommentBtn.frame.size.height+10, 80, 60);
    UILabel *classLab = [[UILabel alloc] initWithFrame:CGRectMake(seeClassification.x, seeClassification.y+seeClassification.height, seeClassification.width, 20)];
 
    classLab.text = @"查看宝贝分类";
    classLab.font=[UIFont systemFontOfSize:10];
    classLab.textAlignment=NSTextAlignmentCenter;
    [self.scrolView addSubview:classLab];
    [self.scrolView addSubview:seeClassification];
    
    //进入商家平台
    UIButton * enterShopBtn=[UIButton buttonWithTarget:self action:@selector(enterBusinessPlatform) image:@"云平台.png"];
    [UIView SetRoundedCorners:enterShopBtn andcornerRadius:10.0 andborderWidth:1.0 andborderColor:[UIColor clearColor]];
    enterShopBtn.frame=CGRectMake((CGRectGetWidth(self.scrolView.frame)-80*2)/3*2 + 80, moreCommentBtn.frame.origin.y+moreCommentBtn.frame.size.height+10, 80, 60);
    UILabel *enterLab = [[UILabel alloc] initWithFrame:CGRectMake(enterShopBtn.x, enterShopBtn.y+enterShopBtn.height, enterShopBtn.width, 20)];
    enterShopBtn.backgroundColor=[UIColor grayColor];
    enterLab.text = @"进入商家平台";
    enterLab.font=[UIFont systemFontOfSize:10];
    enterLab.textAlignment=NSTextAlignmentCenter;
    [self.scrolView addSubview:enterShopBtn];
    [self.scrolView addSubview:enterLab];
    
    //查看图文详情
    UILabel * lab=[[UILabel alloc]initWithFrame:CGRectMake(0, enterLab.frame.size.height+enterLab.frame.origin.y+10, self.view.frame.size.width, 50)];
    lab.textAlignment=NSTextAlignmentCenter;
    lab.text=@"继续拖动，查看图文详情";
    [self.scrolView addSubview:lab];
    
    
    
    self.scrolView.contentSize=CGSizeMake(self.view.frame.size.width, enterLab.height+enterLab.y+55+55);
    self.scrolView.delegate=self;
    
    //heightMax=enterShopBtn.frame.size.height+enterShopBtn.frame.origin.y+55+52;
    


}
#pragma mark --购物车按钮--
- (void)shopCar{
    
    ShopCarVC *shopCar = [[ShopCarVC alloc] init];
    [self pushViewController:shopCar];
}

#pragma mark --查看分类--
- (void)seeClassification{
    DLog(@"查看分类");
}


#pragma mark --进入商家平台--
- (void)enterBusinessPlatform{
    BusinessPlatformVC *patformVC = [[BusinessPlatformVC alloc] init];
    patformVC.shop_id = self.shop_id;
    patformVC.shopName = self.shopName;
    [self pushViewController:patformVC];
}


#pragma mark --查看更多评论--
- (void)moreCommentBtnClick:(UIButton *)button{
    DLog(@"查看更多评论");
}

#pragma mark -- 选择规格--
- (void) chooseBtnClick:(UIButton *)button{
    DLog(@"选择规格");
    ChooseSizeVC *choose = [[ChooseSizeVC alloc] init];
    /** 获取规格 参数是goodID*/
    choose.goods = self.deal;
    
    [self pushViewController:choose];
}


#pragma mark --分享按钮--
- (void)shareBtnClick:(UIControl *)control{
    
    PhotoSeeViewController * con = [[PhotoSeeViewController alloc] init];
    [self pushViewController:con];
    
}

/** 地址*/
- (void)locationBtn:(UIButton *)sender{

    DLog(@"%@",self.deal);
}

#pragma mark --头部视图--
- (void)createHeaderView{

    self.hearderView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 2, self.view.width, self.view.height/3)];
    self.hearderView.pagingEnabled = YES;
    self.hearderView.delegate = self;
   
    NSArray * imgArr1=[self.deal.images componentsSeparatedByString:@";"];
    
    NSMutableArray * imgArr=[NSMutableArray arrayWithArray:imgArr1];
    if ([[imgArr objectAtIndex:imgArr.count-1] isEqualToString:@""]) {
        [imgArr removeObjectAtIndex:imgArr.count-1];
    }
    DLog(@"imgArr is %@ *** imgArr.count is %lu",imgArr,(unsigned long)imgArr.count);
    for ( int i=0; i<imgArr.count; i++) {
        UIImageView * img=[[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width*i, 0, self.view.width, self.view.height/3)];
        NSString * string=[NSString stringWithFormat:@"http://mall.yunku.mobi:8080/mall/upload/goods/%@",imgArr[i]];
        
        NSURL * url=[NSURL URLWithString:string];
        
        [img sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"背景.png"]];
        [self.hearderView addSubview:img];
    }
    
    self.hearderView.contentSize=CGSizeMake(imgArr.count*self.hearderView.width, self.view.height/3);
    self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, self.view.height/3 - 20, self.view.width, 20)];
    self.pageControl.numberOfPages = imgArr.count;//设置总页数
//    self.pageControl.currentPage = 0;//设置当前页数
    // 禁止默认的点击功能
    self.pageControl.enabled = NO;
    // 设置非选中页的圆点颜色
//    self.pageControl.pageIndicatorTintColor = [UIColor redColor];
    // 设置选中页的圆点颜色
    self.pageControl.currentPageIndicatorTintColor = [UIColor orangeColor];
    [self.pageControl setBackgroundColor:[UIColor clearColor]];
    [self.pageControl addTarget:self action:@selector(changImage:) forControlEvents:UIControlEventValueChanged];
    
    [self.scrolView addSubview:self.hearderView];
    [self.scrolView addSubview:self.pageControl];
}

#pragma mark --UIPageControl--
-(void)changImage:(UIPageControl *)sender
{
    self.hearderView.contentOffset = CGPointMake(sender.currentPage*self.view.frame.size.width, 0);
    [self.pageControl updateCurrentPageDisplay];
//    self.pageControl.currentPage = sender.currentPage;
}

#pragma mark --从服务器获取数据--
- (void)loadDataFromServer{
 
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"goodId"] = [NSString stringWithFormat:@"%d",self.goodId];
    //1.商品详情
    NSString *path = [NSString stringWithFormat:@"%@%@",SHOPER,@"html/agoods/detail.do"];
    [manager GET:path parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        DLog(@"responseObject = %@",responseObject);
        GoodsDetail *deal = [GoodsDetail objectWithKeyValues:responseObject];
        DLog(@"----%d",deal.goodId);
        self.deal = deal;
        
        //创建所有视图
        [self createSubViews];
        
    }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {

             DLog(@"请求网络失败");
         }];
}


#pragma mark - UIScorllView--拖动查看更多
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;{
    if(scrollView.contentOffset.y>=270){
        MoreGoodsDetailVC *detailVC = [[MoreGoodsDetailVC alloc] init];
        NSArray * imgArr=[self.deal.images componentsSeparatedByString:@";"];
        detailVC.ImgArr = imgArr;
        [self pushViewController:detailVC];
    }
}
#pragma mark --scrollView偏移走的方法--
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.hearderView) {
        int page = scrollView.contentOffset.x / scrollView.frame.size.width;
        
        // 设置页码
        _pageControl.currentPage = page;
    }
    

}


@end
